<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup">
  <ng-container *ngIf="item.userType !== dataMap.loginUserType.saml.value">
    <lv-form-item *ngIf="setType === dataMap.userFunction.backup.value">
      <lv-form-label>{{
        'protection_openstack_quota_label' | i18n
      }}</lv-form-label>
      <lv-form-control>
        <lv-radio-group
          formControlName="backupQuota"
          [lvGroupName]="'backupQuota'"
        >
          <lv-group [lvGutter]="'24px'">
            <lv-radio [lvValue]="false">
              {{ 'protection_unlimited_quota_label' | i18n }}
            </lv-radio>
            <lv-radio [lvValue]="true">
              {{ 'protection_quota_capacity_label' | i18n }}
            </lv-radio>
          </lv-group>
        </lv-radio-group>
        <ng-container *ngIf="formGroup.value.backupQuota">
          <div class="aui-gutter-column-md"></div>
          <lv-form-item>
            <lv-form-label lvRequired>
              {{ 'system_sftp_quota_label' | i18n }}
            </lv-form-label>
            <lv-form-control [lvErrorTip]="capacityErrorTip">
              <lv-input-group
                [lvAddAfter]="backupUnitTpl"
                class="input-group-select-right"
              >
                <input lv-input formControlName="backupCapacity" />
              </lv-input-group>
              <ng-template #backupUnitTpl>
                <lv-select
                  lvMode="single"
                  [lvOptions]="unitOptions"
                  formControlName="backupCapacityUnit"
                  class="unit-inner-select"
                  lvValueKey="value"
                ></lv-select>
              </ng-template>
              <div class="tips-container">
                <i
                  lv-icon="lv-icon-status-info"
                  lvColorState="true"
                  class="type-icon icon-tips"
                ></i>
                <span class="form-tips">
                  {{ 'system_quota_tips_label' | i18n }}
                  {{
                    item.backupUsedQuota
                      | capacityCalculateLabel: '1.1-3':unitconst.BYTE:true
                  }}
                </span>
              </div>
            </lv-form-control>
          </lv-form-item>
        </ng-container>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item *ngIf="setType === dataMap.userFunction.archive.value">
      <lv-form-label>{{ 'system_archive_quota_label' | i18n }}</lv-form-label>
      <lv-form-control>
        <lv-radio-group
          formControlName="archiveQuota"
          [lvGroupName]="'archiveQuota'"
        >
          <lv-group [lvGutter]="'24px'">
            <lv-radio [lvValue]="false">
              {{ 'protection_unlimited_quota_label' | i18n }}
            </lv-radio>
            <lv-radio [lvValue]="true">
              {{ 'protection_quota_capacity_label' | i18n }}
            </lv-radio>
          </lv-group>
        </lv-radio-group>
        <ng-container *ngIf="formGroup.value.archiveQuota">
          <div class="aui-gutter-column-md"></div>
          <lv-form-item>
            <lv-form-label lvRequired>
              {{ 'system_sftp_quota_label' | i18n }}
            </lv-form-label>
            <lv-form-control [lvErrorTip]="capacityErrorTip">
              <lv-input-group
                [lvAddAfter]="archiveUnitTpl"
                class="input-group-select-right"
              >
                <input lv-input formControlName="archiveCapacity" />
              </lv-input-group>
              <ng-template #archiveUnitTpl>
                <lv-select
                  lvMode="single"
                  [lvOptions]="unitOptions"
                  formControlName="archiveCapacityUnit"
                  class="unit-inner-select"
                  lvValueKey="value"
                ></lv-select>
              </ng-template>
              <div class="tips-container">
                <i
                  lv-icon="lv-icon-status-info"
                  lvColorState="true"
                  class="type-icon icon-tips"
                ></i>
                <span class="form-tips">
                  {{ 'system_quota_tips_label' | i18n }}
                  {{
                    item.cloudArchiveUsedQuota
                      | capacityCalculateLabel: '1.1-3':unitconst.BYTE:true
                  }}
                </span>
              </div>
            </lv-form-control>
          </lv-form-item>
        </ng-container>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container *ngIf="item.userType === dataMap.loginUserType.saml.value">
    <lv-form-item *ngIf="setType === dataMap.userFunction.backup.value">
      <lv-form-label lvRequired>
        {{ 'protection_openstack_quota_label' | i18n }}
      </lv-form-label>
      <lv-form-control [lvErrorTip]="capacityErrorTip">
        <lv-input-group
          [lvAddAfter]="capacityUnitTpl"
          class="input-group-select-right"
        >
          <input lv-input formControlName="backupCapacity" />
        </lv-input-group>
        <ng-template #capacityUnitTpl>
          <lv-select
            lvMode="single"
            [lvOptions]="unitOptions"
            formControlName="backupCapacityUnit"
            class="unit-inner-select"
            lvValueKey="value"
          ></lv-select>
        </ng-template>
        <div class="tips-container">
          <i
            lv-icon="lv-icon-status-info"
            lvColorState="true"
            class="type-icon icon-tips"
          ></i>
          <span class="form-tips">
            <ng-container *ngIf="showSamlQuotaTips">
              {{ 'system_saml_quota_tips_label' | i18n }}
            </ng-container>
            {{ 'common_used_capcity_label' | i18n }}:
            {{
              item.backupUsedQuota
                | capacityCalculateLabel: '1.1-3':unitconst.BYTE:true
            }}
          </span>
        </div>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item *ngIf="setType === dataMap.userFunction.archive.value">
      <lv-form-label lvRequired>
        {{ 'system_archive_quota_label' | i18n }}
      </lv-form-label>
      <lv-form-control [lvErrorTip]="capacityErrorTip">
        <lv-group [lvColumns]="['360px', '100px']">
          <input type="text" formControlName="archiveCapacity" lv-input />
          <lv-select
            lvMode="single"
            [lvOptions]="unitOptions"
            formControlName="archiveCapacityUnit"
            lvValueKey="value"
          >
          </lv-select>
        </lv-group>
        <div class="tips-container">
          <i
            lv-icon="lv-icon-status-info"
            lvColorState="true"
            class="type-icon icon-tips"
          ></i>
          <span class="form-tips">
            <ng-container *ngIf="showSamlQuotaTips">
              {{ 'system_saml_quota_tips_label' | i18n }}
            </ng-container>
            {{ 'common_used_capcity_label' | i18n }}:
            {{
              item.cloudArchiveUsedQuota
                | capacityCalculateLabel: '1.1-3':unitconst.BYTE:true
            }}
          </span>
        </div>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
</lv-form>
